#ifndef COMPLEX_H
#define COMPLEX_H
#include "iostream"
#include "math.h"
using namespace std;

class Complex
{
private:
    double r;
    double i;
    double angle;
    double length;
public:
    Complex(double inputR ,double inputI);
    ~Complex();

    Complex operator+ (const Complex &a)const
    {
        Complex  result(r+a.r,i+a.i);
    return result;
    }
        Complex operator- ( Complex &a)const
        {
        Complex  result(r-a.r,i-a.i);
    return result;
    }

    Complex operator* (const Complex &a)
    {
        Complex result(r*a.r-i*a.i,r*a.i+i*a.r);
        return result;
    }
    Complex operator/ (const Complex&a)
    {
        if(a.length==0)
        {
        cerr<<"幅值不可为0"<<endl;
        exit(1);
        }
        Complex result((r*a.r+i*a.i)/a.length,(i*a.r-r*a.i)/a.length);
        return result;
    }   
    
     friend Complex operator-(const Complex &a)
    {
         Complex result(-a.r,-a.i);
         return result;
    }
    friend Complex operator+(int a ,const Complex&b)
    {
        Complex result(a+b.r,b.i);
        return result ;
    }
        friend Complex operator-(int a ,const Complex&b)
    {
        Complex result(a-b.r,b.i);
        return result ;
    }
    friend ostream& operator<<(ostream &stm,const Complex&a)
    {
        return stm<<"("<<a.r<<","<<a.i<<")";
    }
};

Complex::Complex(double inputR ,double inputI)
{
    r=inputR;
    i=inputI;
    if(i==0)
    {
        if(r>0)
        angle=90;
        else if (r<0)
        angle=270;
        else angle=0;
    }
    else
    angle=atan(r/i);
    length=sqrt(r*r+i*i);
}

Complex::~Complex()
{
}


#endif